<template>
  <div class="menu-bar">
    <transition name="slide-up">
      <div class="menu-wrapper" >
          <!-- <div class="icon-wrapper">
            <span class="iconfont icondaohang" @click="showSetting(3)"></span>
          </div> -->
        <div class="icon-wrapper">
          <span class="iconfont iconjindu" @click="showSetting(2)"></span>
        </div>
        <div class="icon-wrapper">
          <span class="iconfont iconbrightness" @click="showSetting(1)"></span>
        </div>
        <div class="icon-wrapper">
          <span class="iconfont" @click="showSetting(0)">A</span>
        </div>
      </div>
    </transition>
    <transition name="slide-up">
      <div class="setting-wrapper" v-show="ifSettingShow">
        <!--字体设置-->
        <div class="setting-font-size" v-if="showTag === 0">
          <div class="preview" :style="{fontSize: fontSizeList[0].fontSize + 'px'}">A</div>
          <div class="select">
            <div class="select-wrapper" v-for="(item,index) in fontSizeList" :key="index" @click="setFontSize(item.fontSize)">
              <div class="line"></div>
              <div class="point-wrapper">
                <div class="point" v-show="defaultFontSize === item.fontSize">
                  <div class="small-point"></div>
                </div>
              </div>
              <div class="line"></div>
            </div>
          </div>
          <div class="preview" :style="{fontSize: fontSizeList[fontSizeList.length - 1].fontSize + 'px'}">A</div>
        </div>
        <!--主题设置-->
        <div class="setting-theme" v-else-if="showTag === 1">
          <div class="setting-theme-item" v-for="(item,index) in themeList" :key="index" @click="setTheme(index)">
            <div class="preview" :class="{'no-border': item.style.body.background !== '#ffffff'}" :style="{'background': item.style.body.background}"></div>
            <div class="text" :class="{'cur-theme': index === defaultTheme}">{{item.name}}</div>
          </div>
        </div>
        <!--进度条设置-->
        <div class="setting-progress" v-else-if="showTag === 2">
          <div class="progress-wrapper">
            <input class="progress" type="range" max="100" min="0" step="1" :value="progress" :disabled="!bookAvailable" @change="onProgressChange($event.target.value)" @input="onProgressInput($event.target.value)" ref="progress">
          </div>
          <div class="text-wrapper">
            <span>{{bookAvailable ? progress + '%' : '加载中...'}}</span>
          </div>
        </div>
      </div>
    </transition>
    <!-- 目录 -->
    <!-- <content-view :ifShowContent="ifShowContent" v-show="ifShowContent" :navigation="navigation" :bookAvailable="bookAvailable" @jumpTo="jumpTo"></content-view>
    <transition name="fade">
      <div class="content-mask" v-show="ifShowContent" @click="hideContent"></div>
    </transition> -->
  </div>
</template>

<script>
import ContentView from '@/components/Content'
export default {
  name: 'menuBar',
  props: {
    ifTitleAndMenuShow: {
      type: Boolean,
      default: false
    },
    fontSizeList: {
      type: Array
    },
    defaultFontSize: {
      type: Number
    },
    themeList: {
      type: Array
    },
    defaultTheme: {
      type: Number
    },
    bookAvailable: {
      type: Boolean
    },
    navigation: {
      type: Object
    }
  },
  components: {
    ContentView
  },
  data () {
    return {
      ifSettingShow: false,
      showTag: 0,
      progress: 0,
      ifShowContent: false
    }
  },
  methods: {
    showSetting (index) {
      this.showTag = index
      if (index === 3) {
        this.ifSettingShow = false
        this.ifShowContent = true
      } else {
        this.ifSettingShow = true
      }
    },
    hideSetting () {
      this.ifSettingShow = false
      console.log('我是MenuBar子组件 你成功用this.$refs.menuBar.hideSetting()调用到了我')
    },
    setFontSize (fontSize) {
      this.$emit('setFontSize', fontSize)
    },
    setTheme (index) {
      this.$emit('setTheme', index)
    },
    // 拖动进度条时触发事件
    onProgressInput (progress) {
      this.progress = progress
      this.$refs.progress.style.backgroundSize = `${this.progress}% 100%`
    },
    // 进度条松开后触发事件，根据进度条数值跳转到指定位置
    onProgressChange (progress) {
      this.$emit('onProgressChange', progress)
    },
    // 显示目录
    showContent () {
      this.ifShowContent = true
    },
    // 隐藏目录
    hideContent () {
      this.ifShowContent = false
    },
    // 触发跳转
    jumpTo (target) {
      this.$emit('jumpTo', target)
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '~styles/global';
  .menu-bar{
    // position: absolute;
    // display: flex;
    // height: px2rem(48);
    // position: absolute;
    // left: 0;
    // right: 0;
    // bottom: 0;
    // z-index: 101;
    .menu-wrapper{
      width: 75%;
      display: flex;
      height: px2rem(48);
      position: fixed;
      bottom: 0;
      left: 25%;
      // right: 0;
      background-color: #ffffff;
      box-shadow: 0 px2rem(-8) px2rem(8) rgba(0,0,0,0.15);
      z-index: 10100;
      &.hide-box-shadow{
        box-shadow: none;
      }
      .icon-wrapper{
        cursor: pointer;
        flex: 1;
        @include center();
      }
    }
    .setting-wrapper{
      position: absolute;
      height: px2rem(60);
      background: #ffffff;
      box-shadow: 0 px2rem(-8) px2rem(8) rgba(0,0,0,0.15);
      bottom: px2rem(48);
      left: 0;
      right: 0;
      z-index: 101;
      .setting-font-size{
        display: flex;
        width: 75%;
        margin-left: 25%;
        height: 100%;
        .preview{
          flex: 0 0 px2rem(40);
          @include center;
        }
        .select{
          flex: 1;
          display: flex;
          .select-wrapper{
            flex: 1;
            display: flex;
            align-items: center;
            &:first-child{
              .line{
                &:first-child{
                  border-top: none;
                }
              }
            }
            &:last-child{
              .line{
                &:last-child{
                  border-top: none;
                }
              }
            }
            .line{
              flex: 1;
              height: 0;
              border-top: px2rem(1) solid #ccc;
            }
            .point-wrapper{
              flex: 0 0 0;
              width: 0;
              height: px2rem(7);
              border-left: px2rem(1) solid #ccc;
              position: relative;
              .point{
                width: px2rem(20);
                height: px2rem(20);
                border-radius: 50%;
                background-color: #fff;
                border: px2rem(1) solid #ccc;
                box-shadow: 0 px2rem(4) px2rem(4) rgba(0,0,0,0.15);
                position: absolute;
                top: 50%;
                left:50%;
                margin-top: px2rem(-10);
                margin-left: px2rem(-10);
                @include center;
                .small-point{
                  width: px2rem(5);
                  height: px2rem(5);
                  background-color: #000;
                  border-radius: 50%;
                }
              }
            }
          }
        }
      }
      .setting-theme{
        display: flex;
        flex-direction: row;
        width: 75%;
        margin-left: 25%;
        height: 100%;
        .setting-theme-item{
          flex: 1;
          display: flex;
          flex-direction: column;
          padding: px2rem(5);
          box-sizing: border-box;
          .preview{
            flex: 1;
            border: px2rem(1) solid #ccc;
            box-sizing: border-box;
            &.no-border{
              border: none;
            }
          }
          .text{
            @include center;
            flex: 0 0 px2rem(20);
            font-size: px2rem(14);
            color: #ddd;
            &.cur-theme{
              color: #333333;
            }
          }
        }
      }
      .setting-progress{
        width: 75%;
        margin-left: 25%;
        height: 100%;
        display: flex;
        flex-direction: column;
        flex: 1;
        padding: px2rem(10);
        box-sizing: border-box;
        .progress-wrapper{
          flex: 1;
          @include center;
          .progress{
            width: 100%;
            -webkit-appearance: none;
            height: px2rem(2);
            background: -webkit-linear-gradient(#999, #999) no-repeat , #ddd;
            background-size: 0 100%;
            &:focus{
              outline: none;
            }
            &::-webkit-slider-thumb{
              -webkit-appearance: none;
              height: px2rem(20);
              width: px2rem(20);
              border-radius: 50%;
              background: #fff;
              border: px2rem(1) solid #ddd;
              box-shadow: 0 px2rem(4) px2rem(4) rgba(0,0,0,0.15);
            }
          }
        }
        .text-wrapper{
          @include center;
          flex: 0 0 px2rem(22);
          span{
            font-size: px2rem(14)
          }
        }
      }
    }
    .content-mask{
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      z-index: 101;
      background: rgba($color: #000000, $alpha: .5);
      display: flex;
    }
  }
</style>
